# include <iostream>
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>

#ifndef __GNUC__
#include <crtdbg.h>
#endif

# include "StackOSI.h"
#include "LayerFactory.h"
#include "ProtocolFactory.h"
#include <memory>
#include <fstream>
#include <sstream>
#include <boost/shared_ptr.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

class gps_position
{
private:
	friend class boost::serialization::access;
	// When the class Archive corresponds to an output archive, the
	// & operator is defined similar to <<.  Likewise, when the class Archive
	// is a type of input archive the & operator is defined similar to >>.
	template<class Archive>
	void serialize(Archive & ar, const unsigned int version)
	{
		ar & degrees;
		ar & minutes;
		ar & seconds;
	}
	int degrees;
	int minutes;
	float seconds;
public:
	gps_position(){};
	gps_position(int d, int m, float s) :
	degrees(d), minutes(m), seconds(s)
	{}
};


int main(int argc, char** argv) 
{

	// create and open a character archive for output
	std::stringstream ofs;

	// create class instance
	const gps_position g(35, 59, 24.567f);

	// save data to archive
	{
		boost::archive::text_oarchive oa(ofs);
		// write class instance to archive
		oa << g;
		// archive and stream closed when destructors are called
	}

	// ... some time later restore the class instance to its orginal state
	gps_position newg;
	{
		// create and open an archive for input
		boost::archive::text_iarchive ia(ofs);
		// read class state from archive
		ia >> newg;
		// archive and stream closed when destructors are called
	}
 return 0;

	#ifndef __GNUC__
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	#endif

	CByteStream data;
	data.addFront("my_first_packet");

	CPacket packet(&data);

	CStackOSI::getInstance().init();

	std::cout << packet.getBufferContent() << std::endl;
	CStackOSI::getInstance().Encode(packet);
	std::cout << packet.getBufferContent() << std::endl;
	CStackOSI::getInstance().Decode(packet);
	std::cout << packet.getBufferContent() << std::endl;

	return 0;
}
